package com.dimong.www.loan.ui.frag;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.dimong.loan.sdk.ui.frag.BaseFragment;
import com.dimong.www.loan.R;
import com.dimong.www.loan.ui.act.GuidePageActivity;

public class GuidePageFrag extends BaseFragment {
    private ImageView iv_frag_guide;
    private int item;

    public static GuidePageFrag getInstance(int item) {
        GuidePageFrag guidePageFrag = new GuidePageFrag();
        Bundle bundle = new Bundle();
        bundle.putInt("item", item);
        guidePageFrag.setArguments(bundle);
        return guidePageFrag;
    }

    @Override
    public void beforeInitView() {

    }

    @Override
    public void initView() {
        iv_frag_guide = (ImageView) findViewById(R.id.iv_frag_guide);
    }

    @Override
    public void setViewStatus() {
        item = getArguments().getInt("item");
        try {
            switch (item) {
                case 0:
                    Glide.with(getActivity()).load(R.drawable.welcome1).skipMemoryCache(true).placeholder(R.drawable.bg_default).into(iv_frag_guide);
                    break;
                case 1:
                    Glide.with(getActivity()).load(R.drawable.welcome2).skipMemoryCache(true).placeholder(R.drawable.bg_default).into(iv_frag_guide);
                    break;
                case 2:
                    Glide.with(getActivity()).load(R.drawable.welcome3).skipMemoryCache(true).placeholder(R.drawable.bg_default).into(iv_frag_guide);
                    mContentView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            ((GuidePageActivity) getActivity()).finishActivity();
                        }
                    });
                    break;
                default:
                    break;
            }
        } catch (OutOfMemoryError e) {
            System.gc();
        }
    }

    @Override
    public int getViewResourceId() {
        return R.layout.frag_guide;
    }

    public static Bitmap loadResBitmap(Context context, int id) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = false;
        options.inSampleSize = 4;
        Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), id);
        return bmp;
    }
}
